package com.yckj.day08;

/**
 * TODO 测试匿名内部类
 *
 * @author shengyuee
 * @version 1.0
 * 2025/7/25 15:48
 */
public class TestInnerClass {
    public static void main(String[] args) {
        Cat cat = new Cat();
        cat.speek();
        //模拟cat，写一个继承匿名内部类，重写了父类方法，匿名内部类只执行一次
        new Animal(){
            @Override
            public void speek() {
                System.out.println("花猫喵喵叫");
            }
        }.speek();

        // 匿名内部类
        new Thread(){
            @Override
            public void run() {
                for (int i = 1; i <= 5; i++) {
                    System.out.print(i + " ");
                }
            }
        }.start();

        // 接口式匿名内部类
        new Runnable(){
            @Override
            public void run() {
                System.out.println("hello");
            }
        };
    }
}
class Cat extends Animal{

    @Override
    public void speek() {
        System.out.println("猫咪喵喵叫");
    }
}

abstract class Animal{
    public abstract void speek();
}
